from llm_response.llm_response import ask_llm20_1
from uitls.parse.parse_order import parse_order_ids
from uitls.reqquests_post import get_payment_inquiry_pdf
import json
import telebot
import redis
TOKEN = '7702930752:AAGYV0-kGJgMTavSPKxqdgo8tkR_gdthYJI'
bot = telebot.TeleBot(TOKEN)
# 连接本地 Redis（默认端口 6379）
r = redis.Redis(host='127.0.0.1', port=6379, db=0, password='yb@123456')
# r = redis.Redis(host='127.0.0.1', port=6379, db=0, password=None)

def receive_money(country_name_address,message):
    # 4根据订单号，查询是否收到钱
    order_ids = ask_llm20_1(message.text)
    order_data_ids = parse_order_ids(order_ids)
    print("order_id:", order_data_ids)
    if order_data_ids['order_ids']:
        urgent_order = get_payment_inquiry_pdf(country_name_address, order_data_ids['order_ids'][0])
        try:
            data4 = json.loads(urgent_order)
        except json.JSONDecodeError:
            print("不是 JSON，原始输出：", urgent_order)
            data4 = {"address": "", "mid": ""}  # 兜底，直接包一层
        print("urgent_order", urgent_order)
        if data4["status"] == 200:
            try:
                data_order = json.loads(urgent_order)
                if data_order["data"]['orderInfo']['amount'] != "":
                    print("该笔订单的钱不为空")
                    bot.reply_to(message, "该笔订单的钱不为空")
                else:
                    print("该笔订单的钱是空")
                    bot.reply_to(message, "该笔订单的钱为空")
            except json.JSONDecodeError:
                bot.reply_to(message, "老板，订单号不存在，请确认一下订单号是否正确~")
                print("不是 JSON，原始输出：", urgent_order)
        else:
            bot.reply_to(message, "老板，订单号不存在，请确认一下订单号是否正确~")
    else:
        print("无")

